package mortal.game.control
{
    import Message.Game.*;
    import Message.Public.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import flash.display.*;
    import flash.utils.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.model.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.rules.*;
    import mortal.game.scene.ai.*;
    import mortal.game.scene.events.*;
    import mortal.game.scene.layer.utils.*;
    import mortal.game.scene.map.*;
    import mortal.game.scene.player.entity.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.alertwins.*;
    import mortal.game.view.shortcuts.item.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class GuideController extends Controller
    {
        private var _timerKey:uint;
        private var _breaking:Boolean;
        private var _alert:Sprite;
        private var autoPathTimer:Boolean;
        private var autoPathTimerKey:uint;
        private var _autoFightAlert:Sprite;

        public function GuideController()
        {
            
        }

        private function beginGuideTimer(param1:TaskInfo) : void
        {
            if (!param1 || cache.guide.autoType == GuideAutoType.NoAuto)
            {
                
            }
            var _loc_2:* = param1.getTargetByIndex(0);
            if (_loc_2 != null && _loc_2.id != cache.guide.delayId)
            {
                if (param1.status != ETaskStatus._ETaskStatusCanGet && param1.sTask.guide & GuideType.Fly)
                {
                    this.clearGuideTimer();
                    cache.guide.dalayTarget = _loc_2;
                    cache.guide.delayType = 1;
                    cache.guide.delayId = _loc_2.id;
                    if (param1.sTask.type == ETaskType._ETaskTypeCopyStudy && _loc_2.targetType == EntityType.NPC)
                    {
                    }
                    else
                    {
                        this.guideTimer();
                    }
                }
                else if (cache.role.entityInfo.level <= 10 || (param1.status == ETaskStatus._ETaskStatusHadCompleted || param1.sTask.type == ETaskType._ETaskTypeEscort) && param1.sTask.group == ETaskGroup._ETaskGroupMain && (cache.role.entityInfo.level <= 40 || param1.sTask.guide & GuideType.AutoFight))
                {
                    this.clearGuideTimer();
                    cache.guide.dalayTarget = _loc_2;
                    cache.guide.delayType = 0;
                    cache.guide.delayId = _loc_2.id;
                    if (param1.sTask.type == ETaskType._ETaskTypeCopyStudy && _loc_2.targetType == EntityType.NPC)
                    {
                    }
                    else
                    {
                        this.guideTimer();
                    }
                }
            }
            
        }

        public function clearGuideTimer() : void
        {
            this._breaking = false;
            clearTimeout(this._timerKey);
            cache.guide.delayId = 0;
            
        }

        public function breakGuideTimer() : void
        {
            if (!this._breaking)
            {
                clearTimeout(this._timerKey);
                this._breaking = true;
            }
            
        }

        public function continueGuideTimer() : void
        {
            if (this._breaking)
            {
                this.guideTimer();
                this._breaking = false;
            }
            
        }

        private function guideTimer() : void
        {
            this._breaking = false;
            if (cache.guide.dalayTarget == null)
            {
                
            }
            if (cache.guide.delayType == 1)
            {
                Alert.mode = Alert.Mode_NoneNotModal;
                Alert.alertWinRenderer = TimerAlertWin;
                Alert.buttonWidth = 100;
                Alert.timerOut = 5;
                Alert.okLabel = "立刻传送";
                Alert.show("我将施展" + HTMLUtil.addColor("传送之术", "#00B0F0") + "将你传送到" + HTMLUtil.addColor(cache.guide.dalayTarget.name, ColorConfig.instance.getTaskColor("entity_name").color) + "<br>处，准备好了吗？", null, Alert.OK, null, this.onConveyHandler);
                cache.guide.delayFlyTarget = cache.guide.dalayTarget;
            }
            else
            {
                if (GameMapUtil.isCopyMap(MapFileUtil.mapID))
                {
                    
                }
                AIManager.onAutoPathAIControl(cache.guide.dalayTarget, AIType.AI_TaskGuide);
            }
            
        }

        private function onConveyHandler(param1:int) : void
        {
            if (param1 == Alert.OK && cache.guide.dalayTarget != null)
            {
                AIManager.cancelAll();
                AIManager.onAIControl(cache.guide.delayFlyTarget, AIType.AI_Convey);
            }
            cache.guide.delayFlyTarget = null;
            
        }

        private function onBeginGame(event:DataEvent) : void
        {
            var _loc_2:Boolean = false;
            if (event != null)
            {
                _loc_2 = event.data as Boolean;
            }
            var _loc_3:* = cache.task.myTaskList[0];
            if (_loc_3 != null)
            {
                if (_loc_2)
                {
                    this.clearGuideTimer();
                    cache.guide.dalayTarget = _loc_3.getTargetByIndex(0);
                    cache.guide.delayType = 0;
                    cache.guide.delayId = cache.guide.dalayTarget.id;
                    this.guideTimer();
                }
                else
                {
                    this.beginGuideTimer(_loc_3);
                }
            }
            this.guideCheck(cache.task.myTaskList);
            
        }

        protected function onTaskListRes(param1:Array) : void
        {
            if (cache.role.entityInfo.level == 1)
            {
                GameManager.instance.popupWindow(ModuleType.GuideWelcome);
            }
            else
            {
                this.onBeginGame(null);
            }
            
        }

        protected function onTaskAddRes(param1:TaskInfo) : void
        {
            if (param1.sTask.guide & GuideType.FristFight)
            {
            }
            else
            {
                this.checkTask(param1, 1);
            }
            
        }

        protected function onTaskGetRes(param1:Object) : void
        {
            var _loc_4:TaskTargetInfo = null;
            if (param1 == null || param1.task == null)
            {
                
            }
            var _loc_2:* = param1.task;
            if (_loc_2 && _loc_2.sTask.group == ETaskGroup._ETaskGroupLoopBook)
            {
                
            }
            var _loc_3:* = TaskShowConfig.instance.getShowTalkById(_loc_2.sTask.getTalkId);
            if (_loc_3 != null)
            {
                cache.guide.showTaskId = _loc_2.sTask.code;
                MsgManager.showTaskTarget(_loc_3);
            }
            if (_loc_2 && _loc_2.sTask.guide & GuideType.FristFight)
            {
                cache.guide.dalayTarget = _loc_2.getTargetByIndex(0);
                cache.guide.delayType = 0;
                cache.guide.delayId = cache.guide.dalayTarget.id;
                Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_SceneFight, GuideOptType.GuideFirstAttack));
                
            }
            if (_loc_2 && _loc_2.sTask.guide & GuideType.FuBenGuide)
            {
                this.clearGuideTimer();
                if (this.hasCanGetTask(_loc_2))
                {
                    
                }
                cache.guide.dalayTarget = _loc_2.getTargetByIndex(0);
                cache.guide.delayType = 0;
                cache.guide.delayId = cache.guide.dalayTarget.id;
                this.guideTimer();
                
            }
            if (_loc_2 && cache.guide.petGuide)
            {
                cache.guide.dalayTarget = _loc_2.getTargetByIndex(0);
                cache.guide.delayType = 0;
                cache.guide.delayId = cache.guide.dalayTarget.id;
                Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_ModuleOpen, ModuleType.Pets));
                
            }
            if (_loc_2 && _loc_2.sTask.guide & GuideType.GuideNPCEffect)
            {
                this.clearGuideTimer();
                cache.guide.guideNpcEffect = true;
                if (this.hasCanGetTask(_loc_2))
                {
                    
                }
                cache.guide.dalayTarget = _loc_2.getTargetByIndex(0);
                cache.guide.delayType = 0;
                cache.guide.delayId = cache.guide.dalayTarget.id;
                this.guideTimer();
                
            }
            if (_loc_2.sTask.type == ETaskType._ETaskTypeRefreshPetGrowth)
            {
                cache.guide.guidePetRefresh = true;
                cache.guide.dalayTarget = _loc_2.getTargetByIndex(0);
                cache.guide.delayType = 0;
                cache.guide.delayId = cache.guide.dalayTarget.id;
                Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_ModuleOpen, ModuleType.Pets));
                
            }
            if (_loc_2.sTask.type == ETaskType._ETaskTypeWeaponStrengthen)
            {
                cache.guide.guideEquipRefresh = true;
                cache.guide.dalayTarget = _loc_2.getTargetByIndex(0);
                cache.guide.delayType = 0;
                cache.guide.delayId = cache.guide.dalayTarget.id;
                Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_ModuleOpen, ModuleType.Build));
                
            }
            if (_loc_2.sTask.type == ETaskType._ETaskTypePetSite)
            {
                cache.guide.guidePetSite = true;
            }
            if (_loc_2 && _loc_2.sTask.type == ETaskType._ETaskTypeCopyStudy)
            {
                cache.guide.copyStudy = true;
            }
            if (_loc_2 && _loc_2.sTask.type == ETaskType._ETaskTypeGroupKillBoss)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_ModuleOpen, ModuleType.Group));
            }
            if (cache.guide.hasCanGetTask)
            {
                if (this.hasCanGetTask(_loc_2))
                {
                    
                }
                this.guideTimer();
            }
            else
            {
                if (this.hasCanGetTask(_loc_2))
                {
                    
                }
                _loc_4 = _loc_2.getTargetByIndex(0);
                if (_loc_4 && _loc_4.targetType == EntityType.Boss && cache.role.entityInfo.level >= 10 && cache.role.entityInfo.level <= 30)
                {
                    cache.guide.dalayTarget = _loc_2.getTargetByIndex(0);
                    cache.guide.delayType = 0;
                    cache.guide.delayId = cache.guide.dalayTarget.id;
                    this.guideTimer();
                }
                else
                {
                    this.beginGuideTimer(_loc_2);
                }
            }
            
        }

        private function hasCanGetTask(param1:TaskInfo) : Boolean
        {
            var _loc_2:TaskTargetInfo = null;
            if (cache.dialog.hasCanGetTask())
            {
                cache.guide.hasCanGetTask = true;
                _loc_2 = param1.getTargetByIndex(0);
                if (_loc_2 != null)
                {
                    cache.guide.dalayTarget = _loc_2;
                    cache.guide.delayType = 0;
                    cache.guide.delayId = _loc_2.id;
                }
            }
            else
            {
                cache.guide.hasCanGetTask = false;
            }
            return cache.guide.hasCanGetTask;
        }

        protected function onCanGetTaskAdd(param1:Array) : void
        {
            var _loc_3:TaskTargetInfo = null;
            if (param1.length == 0)
            {
                
            }
            var _loc_2:* = param1[0];
            if (!_loc_2)
            {
                
            }
            if (cache.guide.guideSkillLearn)
            {
                cache.guide.dalayTarget = _loc_2.getTargetByIndex(0);
                cache.guide.delayType = 0;
                cache.guide.delayId = cache.guide.dalayTarget.id;
                
            }
            if (cache.guide.guideUseDrug)
            {
                cache.guide.dalayTarget = _loc_2.getTargetByIndex(0);
                cache.guide.delayType = 0;
                cache.guide.delayId = cache.guide.dalayTarget.id;
                
            }
            if (cache.guide.guideItemAlert)
            {
                _loc_3 = _loc_2.getTargetByIndex(0);
                if (_loc_3 != null)
                {
                    cache.guide.dalayTarget = _loc_3;
                    cache.guide.delayType = 0;
                    cache.guide.delayId = _loc_3.id;
                    if (_loc_2.status != ETaskStatus._ETaskStatusCanGet && _loc_2.sTask.guide & GuideType.Fly)
                    {
                        cache.guide.delayType = 1;
                    }
                }
                
            }
            if (_loc_2.sTask.group == ETaskGroup._ETaskGroupLoopBook)
            {
                
            }
            this.beginGuideTimer(_loc_2);
            
        }

        protected function onTaskUpdateRes(param1:Array) : void
        {
            var _loc_2:int = 0;
            var _loc_4:TaskInfo = null;
            var _loc_5:Boolean = false;
            var _loc_3:* = param1.length;
            var _loc_6:Boolean = true;
            while (_loc_2 < _loc_3)
            {
                
                _loc_4 = param1[_loc_2];
                if (_loc_4.status == ETaskStatus._ETaskStatusHadCompleted)
                {
                    this.onTaskHadCom(_loc_4);
                }
                else
                {
                    if (cache.guide.autoType != GuideAutoType.NoAuto)
                    {
                        if (_loc_4.sTask.type == ETaskType._ETaskTypeCopyStudy)
                        {
                            if (!_loc_4.preTargetInfo || _loc_4.preTargetInfo.targetType != EntityType.NPC)
                            {
                                this.beginGuideTimer(_loc_4);
                            }
                        }
                        else
                        {
                            this.beginGuideTimer(_loc_4);
                        }
                    }
                    if (_loc_4.updateInfo && _loc_4.updateInfo != "")
                    {
                        MsgManager.addBroadCast(_loc_4.updateInfo);
                        MsgManager.addTipText(_loc_4.updateInfo);
                    }
                }
                _loc_5 = this.checkTask(_loc_4, 2);
                if (_loc_5 == true && _loc_6 == true)
                {
                    _loc_6 = false;
                }
                _loc_2++;
            }
            if (_loc_6 == true)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_PathHide));
            }
            
        }

        protected function onTaskHadCom(param1:TaskInfo) : void
        {
            if (param1.sTask.group == ETaskGroup._ETaskGroupLoopBook)
            {
                
            }
            if (param1.sTask.type == ETaskType._ETaskTypeCopyStudy)
            {
                AIManager.onAutoPathAIControl(param1.getTargetByIndex(0));
                
            }
            if (cache.role.entityInfo.level <= 40 && cache.role.entityInfo.level > 10 && GameMapUtil.isCopyMap(MapFileUtil.mapID) && cache.scene.isCopyNpc(param1.sTask.endNpc))
            {
                if (cache.copy.copyInfo.code == 101)
                {
                    cache.guide.copyTaskEnd = true;
                    cache.guide.copyTaskEndNpc = param1.getTargetByIndex(0);
                    setTimeout(this.stopFightInCopy, 500);
                    MsgManager.showCopyEndStr("独角龙犀已死，冰龙洞将在n秒后坍塌，请火速离开！", 1, 30, this.onCopyEndTimeCom);
                    Alert.alertWinRenderer = TimerAlertWin;
                    Alert.buttonWidth = 100;
                    Alert.timerOut = 30;
                    Alert.okLabel = "马上离开";
                    Alert.calcelLabel = "稍后离开";
                    Alert.show("冰龙洞已经开始坍塌，是否确定马上离开？<br>" + HTMLUtil.addColor("（离开时记得带走地上的宝物哦！空格键可以快速拾取）", "#00ff00"), null, Alert.OK | Alert.CANCEL, null, this.onExitAlertHandler);
                }
                
            }
            if (param1.sTask.type == ETaskType._ETaskTypePetSite)
            {
                cache.guide.guidePetSite = false;
            }
            this.beginGuideTimer(param1);
            
        }

        private function onExitAlertHandler(param1:int) : void
        {
            if (param1 == Alert.OK)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CopyLeaveWithoutComfirm));
            }
            else
            {
                MsgManager.hideCopyEndStr();
            }
            
        }

        private function stopFightInCopy() : void
        {
            AIManager.cancelAll();
            
        }

        private function onCopyEndTimeCom() : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CopyLeaveWithoutComfirm));
            
        }

        protected function onTaskCancelRes(param1:STask) : void
        {
            if (param1.guide != 0)
            {
                this.guideCheck(cache.task.myTaskList);
            }
            
        }

        protected function onTaskEndRes(param1:Object) : void
        {
            if (param1 == null || param1.task == null)
            {
                
            }
            var _loc_2:* = param1.task;
            if (_loc_2.sTask.code == cache.guide.showTaskId)
            {
                cache.guide.showTaskId = 0;
                MsgManager.removeTaskTarget();
            }
            if (_loc_2.sTask.guide & GuideType.GuideSkillLearn)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_SkillLearn));
                
            }
            if (cache.guide.guideItemAlert)
            {
            }
            this.checkTask(_loc_2, 3);
            
        }

        protected function onConveyRes(event:DataEvent) : void
        {
            cache.guide.delayFlyTarget = null;
            var _loc_2:* = event.data as TaskTargetInfo;
            if (_loc_2 == null)
            {
                
            }
            if (GuideTipsManager.target == null)
            {
                
            }
            if (_loc_2 == GuideTipsManager.target)
            {
                GuideTipsManager.hideGuideTips();
            }
            
        }

        private function onOutNpcDistance(event:DataEvent) : void
        {
            this.guideCheck(cache.task.myTaskList);
            
        }

        private function onUpdateCareer(event:DataEvent) : void
        {
            this.guideCheck(cache.task.myTaskList);
            
        }

        private function guideCheck(param1:Array) : void
        {
            var _loc_4:TaskInfo = null;
            var _loc_5:TaskTargetInfo = null;
            var _loc_6:Boolean = false;
            var _loc_2:int = 0;
            var _loc_3:* = param1.length;
            while (_loc_2 < _loc_3)
            {
                
                _loc_4 = param1[_loc_2];
                _loc_6 = this.checkTask(_loc_4);
                if (_loc_6)
                {
                    break;
                }
                _loc_2++;
            }
            if (!_loc_6)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_PathHide));
            }
            
        }

        private function checkTask(param1:TaskInfo, param2:int = 0) : Boolean
        {
            var _loc_3:Boolean = false;
            var _loc_5:OperateInfo = null;
            var _loc_6:OperateInfo = null;
            var _loc_7:Array = null;
            var _loc_8:ItemData = null;
            var _loc_9:MsgTipInfo = null;
            if (!param1 || !param1.sTask)
            {
                return false;
            }
            var _loc_4:* = param1.getTargetByIndex(0);
            if (!param1.getTargetByIndex(0))
            {
                return false;
            }
            if (param1.sTask.guide & GuideType.GuideTips)
            {
                if (_loc_4.targetType == EntityType.Boss)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_BossFind, param1));
                    _loc_3 = true;
                }
                else if (_loc_4.targetType == EntityType.NPC)
                {
                    if (cache.dialog.npcInfo != null && cache.dialog.npcInfo.tnpc.npcId == _loc_4.id && !GameController.dialog.view.isHide)
                    {
                    }
                    else
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_NPCFind, param1));
                    }
                    _loc_3 = true;
                }
            }
            else if (param1.sTask.guide & GuideType.Fly)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_Fly, param1));
                _loc_3 = true;
            }
            if (param1.sTask.guide & GuideType.UpdateCareer)
            {
                if (cache.guide.selectedCareer)
                {
                    AIManager.onAutoPathAIControl(_loc_4);
                }
                else if (cache.role.entityInfo.career == ECareer._ECareerNewPlayer)
                {
                    GameController.career.view.show();
                }
                _loc_3 = true;
            }
            else if (param1.sTask.guide & GuideType.FristFight && param2 == 1)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_SceneFight, GuideOptType.GuideFirstAttack));
                _loc_3 = true;
            }
            else if (param1.sTask.guide & GuideType.FristPick && param2 == 2 && param1.sTask.processes[0].contents[1] == 1)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_SceneFight, GuideOptType.GuideFirstPick));
                _loc_3 = true;
            }
            else if (param1.sTask.guide & GuideType.AutoFight && param2 == 1)
            {
                if (AutoFightRule.isAutoFight())
                {
                }
                else
                {
                    cache.guide.autoFightGuide = true;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_Hang));
                    _loc_3 = true;
                }
            }
            else if (param1.sTask.guide & GuideType.LifeBar && param2 == 1)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_LifeBar));
                _loc_3 = true;
            }
            else if (param1.sTask.guide & GuideType.FuBenGuide && param2 == 1)
            {
                cache.guide.fuBenGuide = true;
                _loc_3 = true;
            }
            else if (param1.sTask.type == ETaskType._ETaskTypeMallBuy && param2 == 1)
            {
                if (cache.dialog.npcInfo && cache.guide.npcBuyTask)
                {
                    _loc_5 = cache.dialog.operateList[0];
                    if (_loc_5 != null)
                    {
                        GameManager.instance.popupWindow(_loc_5.operateId);
                    }
                }
                return true;
            }
            else if (param1.sTask.type == ETaskType._ETaskTypeRepair && param2 == 1)
            {
                if (cache.dialog.npcInfo && cache.guide.npcRepairTask)
                {
                    _loc_6 = cache.dialog.operateList[0];
                    if (_loc_6 != null)
                    {
                        GameManager.instance.popupWindow(_loc_6.operateId);
                    }
                }
                return true;
            }
            else if (param1.sTask.guide & GuideType.GiftPackUse && param2 == 3)
            {
                _loc_7 = cache.pack.backPackCache.getTypeLevelItems(ECategory._ECategoryProp, EProp._EPropFixGiftBag, 10);
                if (_loc_7.length > 0)
                {
                    _loc_8 = _loc_7[0];
                    _loc_9 = new MsgTipInfo();
                    _loc_9.contentArr.push("您有[" + _loc_8.itemInfo.item.name + "]可使用，打开可获得丰厚礼品");
                    _loc_9.colorArr.push(16777215);
                    _loc_9.itemDataArr.push(_loc_8);
                    _loc_9.itemColorArr.push(ColorConfig.instance.getItemColor(_loc_8.itemInfo.item.color).color);
                    _loc_9.isClick = 1;
                    _loc_9.isAutoHide = true;
                    _loc_9.clickEventArr.push(EventName.ShowBackPackModule);
                    Dispatcher.dispatchEvent(new DataEvent(EventName.MsgTipDateChange, _loc_9));
                    return true;
                }
            }
            else
            {
                if (param1.sTask.guide & GuideType.DailyModule && param2 == 3)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.GuideDailyModule));
                    return true;
                }
                if (param1.sTask.type == ETaskType._ETaskTypeApplyGuild && (param2 == 1 || param2 == 0 && param1.status == ETaskStatus._ETaskStatusNotCompleted))
                {
                    cache.guide.guideApplyGuild = true;
                    _loc_3 = true;
                }
                else if (param1.sTask.type == ETaskType._ETaskTypeRefreshPetGrowth && (param2 == 0 || param2 == 1) && !cache.guide.guidePetRefresh && !cache.guide.guidePetRefreshEd)
                {
                    cache.guide.guidePetRefresh = true;
                    cache.guide.dalayTarget = param1.getTargetByIndex(0);
                    cache.guide.delayType = 0;
                    cache.guide.delayId = cache.guide.dalayTarget.id;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_ModuleOpen, ModuleType.Pets));
                    _loc_3 = true;
                }
                else if (param1.sTask.type == ETaskType._ETaskTypeWeaponStrengthen && (param2 == 0 || param2 == 1) && !cache.guide.guideEquipRefresh)
                {
                    cache.guide.guideEquipRefresh = true;
                    cache.guide.dalayTarget = param1.getTargetByIndex(0);
                    cache.guide.delayType = 0;
                    cache.guide.delayId = cache.guide.dalayTarget.id;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_ModuleOpen, ModuleType.Build));
                    _loc_3 = true;
                }
                else if (param1.sTask.type == ETaskType._ETaskTypePetSite && (param2 == 0 || param2 == 1) && param1.status == ETaskStatus._ETaskStatusNotCompleted && !cache.guide.guidePetSite)
                {
                    cache.guide.guidePetSite = true;
                }
                else if (param1.sTask.guide & GuideType.GuideCollection && (param2 == 1 || param2 == 0))
                {
                    if (param2 == 1)
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_VIPFly, param1));
                    }
                    _loc_3 = true;
                }
                else if (param1.endLevel > cache.role.entityInfo.level && param2 == 1)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_DailyAct, param1));
                    _loc_3 = true;
                }
            }
            return _loc_3;
        }

        private function onAutoFightAlertHandler(param1:int) : void
        {
            if (param1 == Alert.OK)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.AutoFightKeyToFight));
            }
            this._autoFightAlert = null;
            
        }

        private function onEscortIsAttacked(event:DataEvent) : void
        {
            if (cache.status.currentStatus == StatusType.AutoPath)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.AutoPathEnd));
            }
            AIManager.cancelAll();
            RolePlayer.instance.stopWalking();
            
        }

        private function onSceneUpdateHandler(event:DataEvent) : void
        {
            var _loc_2:TaskInfo = null;
            var _loc_3:TaskTargetInfo = null;
            if (GameMapUtil.isCopyMap(MapFileUtil.mapID))
            {
                if (cache.guide.copyStudy)
                {
                    if (cache.guide.dalayTarget && cache.guide.dalayTarget.mapId == MapFileUtil.mapID)
                    {
                        AIManager.onAutoPathAIControl(cache.guide.dalayTarget);
                    }
                }
                else if (cache.guide.fuBenGuide)
                {
                    if (cache.copy.copyInfo.code == 101)
                    {
                        Alert.okLabel = "开始战斗";
                        Alert.buttonWidth = 100;
                        Alert.show("你已经身处<font color=\'#00ff00\'>" + cache.copy.copyInfo.name + "</font>中，邪恶的妖魔就在前面<br>拿起你的武器<font color=\'#ff00ff\'>开始战斗</font>吧！", null, Alert.OK, null, this.onCopyAutoFightAlertHandler);
                    }
                    setTimeout(this.onEnterCopyGuide, 2000);
                }
            }
            else if (cache.guide.fuBenGuide)
            {
                cache.guide.fuBenGuide = false;
                if (cache.guide.copyTaskEnd)
                {
                    cache.guide.copyTaskEnd = false;
                    MsgManager.hideCopyEndStr();
                    if (cache.guide.copyTaskEndNpc)
                    {
                        AIManager.onAutoPathAIControl(cache.guide.copyTaskEndNpc);
                    }
                }
                if (cache.guide.guideTargetPoint)
                {
                    cache.guide.guideTargetEntity = null;
                    cache.guide.guideTargetPoint = false;
                    RolePlayer.instance.removeTargetTilePoint();
                }
            }
            else if (cache.guide.copyStudy)
            {
                cache.guide.copyStudy = false;
                _loc_2 = cache.task.getCopyStudyTask();
                if (_loc_2 && _loc_2.status == ETaskStatus._ETaskStatusHadCompleted)
                {
                    _loc_3 = _loc_2.getTargetByIndex(0);
                    if (_loc_3 != null)
                    {
                        AIManager.onAutoPathAIControl(_loc_3);
                    }
                }
            }
            
        }

        private function onEnterCopyGuide() : void
        {
            var _loc_2:BossRefreshInfo = null;
            var _loc_1:* = ThingUtil.entityUtil.getRandomMonster(EntityType.Boss, null, false, true, false, false) as MonsterPlayer;
            if (_loc_1 != null)
            {
                cache.guide.guideTargetPoint = true;
                cache.guide.guideTargetEntity = _loc_1;
                RolePlayer.instance.setTargetTilePoint(_loc_1.currentPoint.x, _loc_1.currentPoint.y);
            }
            else
            {
                _loc_2 = cache.scene.getNextRefreshPoint(-1);
                if (_loc_2 != null)
                {
                    cache.guide.guideTargetPoint = true;
                    cache.guide.guideTargetEntity = _loc_2;
                    RolePlayer.instance.setTargetTilePoint(_loc_2.px, _loc_2.py);
                }
            }
            
        }

        private function onCopyAutoFightAlertHandler(param1:int) : void
        {
            if (param1 == Alert.OK)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.AutoFightKeyToFight));
            }
            
        }

        private function onGuideItemUsed(event:DataEvent) : void
        {
            if (!this._breaking)
            {
                clearTimeout(this._timerKey);
                this.guideTimer();
            }
            
        }

        private function onFirstAttackHide(event:DataEvent) : void
        {
            if (!this._breaking)
            {
                clearTimeout(this._timerKey);
                this.guideTimer();
            }
            
        }

        private function onShopCloseHandler(event:DataEvent) : void
        {
            this.hideNpcEffectGuide();
            
        }

        private function onWareCloseHandler(event:DataEvent) : void
        {
            if (this.hideNpcEffectGuide())
            {
                Dispatcher.removeEventListener(EventName.WareClose, this.onWareCloseHandler);
            }
            
        }

        private function onEquipmentWindowCloseHandler(event:DataEvent) : void
        {
            this.hideNpcEffectGuide();
            if (cache.guide.guideEquipRefresh)
            {
                cache.guide.guideEquipRefresh = false;
                this.guideTimer();
            }
            
        }

        private function onPetForgetCloseHandler(event:DataEvent) : void
        {
            this.hideNpcEffectGuide();
            
        }

        private function hideNpcEffectGuide() : Boolean
        {
            if (cache.dialog.npcInfo && cache.guide.isGuideNpcEffect(cache.dialog.npcInfo.tnpc.npcId))
            {
                cache.guide.guideNpcEffect = false;
                if (!this._breaking)
                {
                    clearTimeout(this._timerKey);
                    this.guideTimer();
                }
                if (!GameController.pack.view.isHide)
                {
                    GameController.pack.view.hide();
                }
                return true;
            }
            return false;
        }

        private function onPetBattleHandler(event:DataEvent) : void
        {
            if (cache.guide.petGuide)
            {
                cache.guide.petBattle = true;
                Dispatcher.removeEventListener(EventName.PetBattle, this.onPetBattleHandler);
            }
            
        }

        private function onPetBattleSuccessHandler(event:DataEvent) : void
        {
            if (cache.guide.petGuide || cache.guide.petBattle)
            {
                GameController.pet.view.hide();
                cache.guide.petGuide = false;
                Dispatcher.removeEventListener(EventName.PetBattleSuccess, this.onPetBattleSuccessHandler);
                this.guideTimer();
            }
            
        }

        private function onPetWindowCloseHandler(event:DataEvent) : void
        {
            var _loc_2:SPetInfo = null;
            if (cache.guide.petGuide)
            {
                cache.guide.petGuide = false;
                if (!cache.guide.petBattle)
                {
                    this.guideTimer();
                    _loc_2 = event.data as SPetInfo;
                    if (_loc_2 != null)
                    {
                        cache.guide.petBattle = true;
                        Dispatcher.removeEventListener(EventName.PetBattle, this.onPetBattleHandler);
                        Dispatcher.dispatchEvent(new DataEvent(EventName.PetBattle, _loc_2));
                    }
                }
            }
            if (cache.guide.guidePetRefresh)
            {
                cache.guide.guidePetRefreshEd = true;
                cache.guide.guidePetRefresh = false;
                this.guideTimer();
            }
            
        }

        private function onSkillWindowCloseHandler(event:DataEvent) : void
        {
            if (cache.guide.guideSkillLearn)
            {
                cache.guide.guideSkillLearn = false;
                Dispatcher.removeEventListener(EventName.SkillWindowClose, this.onSkillWindowCloseHandler);
                this.guideTimer();
            }
            
        }

        private function onGuildApplySuccessHandler(event:DataEvent) : void
        {
            if (cache.guide.guideApplyGuild)
            {
                cache.guide.guideApplyGuild = false;
                Dispatcher.removeEventListener(EventName.GuildApplySuccess, this.onGuildApplySuccessHandler);
            }
            
        }

        private function onPackWindowCloseHandler(event:DataEvent) : void
        {
            var _loc_2:Array = null;
            var _loc_3:Array = null;
            if (cache.guide.guideUseDrug)
            {
                if (!cache.guide.guideUseHong)
                {
                    _loc_2 = cache.pack.backPackCache.getItemsByJudge(ItemsUtil.isChangeshengdan);
                    if (_loc_2.length > 0)
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.ItemUseReq, _loc_2[0]));
                    }
                    cache.guide.guideUseHong = true;
                }
                if (!cache.guide.guideUseLan)
                {
                    _loc_3 = cache.pack.backPackCache.getItemsByJudge(ItemsUtil.isButianwan);
                    if (_loc_3.length > 0)
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.ItemUseReq, _loc_3[0]));
                    }
                    cache.guide.guideUseLan = true;
                }
                cache.guide.guideUseDrug = false;
                Dispatcher.removeEventListener(EventName.PackWindowClose, this.onPackWindowCloseHandler);
                this.guideTimer();
            }
            
        }

        public function breakAutoPath() : void
        {
            if (cache.status.currentStatus == StatusType.AutoPath)
            {
                if (this.autoPathTimer)
                {
                    this.autoPathTimer = false;
                    clearTimeout(this.autoPathTimerKey);
                }
                else
                {
                    this.autoPathTimer = true;
                    this.autoPathTimerKey = setTimeout(this.onAutoPathTimer, 1000);
                }
            }
            else
            {
                this.autoPathTimer = false;
                clearTimeout(this.autoPathTimerKey);
            }
            
        }

        private function onAutoPathTimer() : void
        {
            this.autoPathTimer = false;
            AIManager.onAutoPathAIControl(cache.guide.dalayTarget);
            
        }

        private function onAIFightInDisHandler(event:DataEvent) : void
        {
            var _loc_3:Array = null;
            var _loc_4:TaskInfo = null;
            var _loc_2:* = event.data as MonsterPlayer;
            if (_loc_2 != null)
            {
                if (cache.role.entityInfo.level <= 10)
                {
                    if (!AutoFightRule.isAutoFight())
                    {
                        if (cache.task.isTaskMonster(_loc_2.bossCode, ETaskGroup._ETaskGroupMain))
                        {
                            Dispatcher.dispatchEvent(new DataEvent(EventName.AutoFightGuideBegin));
                        }
                    }
                }
                else if (cache.role.entityInfo.level <= 40)
                {
                    if (this._autoFightAlert == null || !this._autoFightAlert.parent)
                    {
                        if (!AutoFightRule.isAutoFight() && AutoFightRule.flag != AutoFightRule.AutoFightHide)
                        {
                            _loc_3 = cache.task.getTaskByMonster(_loc_2.bossCode, ETaskGroup._ETaskGroupMain);
                            if (_loc_3 != null && _loc_3.length > 0)
                            {
                                _loc_4 = _loc_3[0];
                                if (!_loc_4.hasGuideAutoFight && !(_loc_4.sTask.guide & GuideType.AutoFight) && !GameMapUtil.isCopyMap(MapFileUtil.mapID))
                                {
                                    _loc_4.hasGuideAutoFight = true;
                                    Alert.showCloseBtn = true;
                                    Alert.okLabel = "开始挂机";
                                    Alert.buttonWidth = 100;
                                    this._autoFightAlert = Alert.show("使用<font color=\'#ff00ff\'>挂机</font><font color=\'#ffff00\'>（快捷键A）</font>可轻松<font color=\'#00ff00\'>自动完成</font>打怪和采集", null, Alert.OK, null, this.onAutoFightAlertHandler);
                                }
                            }
                        }
                    }
                }
            }
            
        }

        private function onAutoFightBeginHandler(event:DataEvent) : void
        {
            if (this._autoFightAlert)
            {
                if (this._autoFightAlert.parent)
                {
                    this._autoFightAlert.parent.removeChild(this._autoFightAlert);
                }
                this._autoFightAlert = null;
            }
            
        }

        private function onPlayerFireHandler(event:PlayerEvent) : void
        {
            if (cache.guide.guideTargetPoint && GameController.scene.selectEntity != null)
            {
                if (!cache.copy.isProcessEnd())
                {
                    cache.guide.guideTargetPoint = false;
                    cache.guide.guideTargetEntity = null;
                    RolePlayer.instance.removeTargetTilePoint();
                }
            }
            
        }

        private function onCopyProcessUpdate(param1:Object) : void
        {
            var _loc_2:SPassPoint = null;
            if (cache.guide.fuBenGuide)
            {
                if (cache.copy.isProcessEnd())
                {
                    _loc_2 = cache.scene.getNearlyPassPoint();
                    if (_loc_2 != null)
                    {
                        setTimeout(this.copyProcessEnd, 1000, _loc_2);
                    }
                }
            }
            
        }

        private function copyProcessEnd(param1:SPassPoint) : void
        {
            cache.guide.guideTargetPoint = true;
            cache.guide.guideTargetEntity = param1;
            RolePlayer.instance.setTargetTilePoint(param1.point.x, param1.point.y);
            
        }

        private function onGridWorkEnd(event:PlayerEvent) : void
        {
            var _loc_2:MonsterPlayer = null;
            if (cache.guide.guideTargetPoint && cache.guide.guideTargetEntity)
            {
                if (cache.guide.guideTargetEntity is SPassPoint)
                {
                    RolePlayer.instance.setTargetTilePoint((cache.guide.guideTargetEntity as SPassPoint).point.x, (cache.guide.guideTargetEntity as SPassPoint).point.y);
                }
                else if (cache.guide.guideTargetEntity is MonsterPlayer)
                {
                    RolePlayer.instance.setTargetTilePoint((cache.guide.guideTargetEntity as MonsterPlayer).currentPoint.x, (cache.guide.guideTargetEntity as MonsterPlayer).currentPoint.y);
                }
                else if (cache.guide.guideTargetEntity is BossRefreshInfo)
                {
                    _loc_2 = ThingUtil.entityUtil.getRandomMonster(EntityType.Boss, null, false, true, false, false) as MonsterPlayer;
                    if (_loc_2 != null)
                    {
                        cache.guide.guideTargetEntity = _loc_2;
                        RolePlayer.instance.setTargetTilePoint(_loc_2.currentPoint.x, _loc_2.currentPoint.y);
                    }
                    else
                    {
                        RolePlayer.instance.setTargetTilePoint((cache.guide.guideTargetEntity as BossRefreshInfo).px, (cache.guide.guideTargetEntity as BossRefreshInfo).py);
                    }
                }
            }
            
        }

        private function onCopyResetHandler(event:DataEvent) : void
        {
            if (cache.guide.guideTargetPoint && GameController.scene.selectEntity != null)
            {
                cache.guide.guideTargetPoint = false;
                cache.guide.guideTargetEntity = null;
                RolePlayer.instance.removeTargetTilePoint();
            }
            
        }

        override protected function initServer() : void
        {
            super.initServer();
            NetDispatcher.addCmdListener(ServerCommand.TaskListRes, this.onTaskListRes);
            NetDispatcher.addCmdListener(ServerCommand.TaskAdd, this.onTaskAddRes);
            NetDispatcher.addCmdListener(ServerCommand.TaskGetRes, this.onTaskGetRes);
            NetDispatcher.addCmdListener(ServerCommand.TaskUpdate, this.onTaskUpdateRes);
            NetDispatcher.addCmdListener(ServerCommand.TaskCancelRes, this.onTaskCancelRes);
            NetDispatcher.addCmdListener(ServerCommand.CanGetListAdd, this.onCanGetTaskAdd);
            NetDispatcher.addCmdListener(ServerCommand.CanGetListRefresh, this.onCanGetTaskAdd);
            NetDispatcher.addCmdListener(ServerCommand.TaskEndRes, this.onTaskEndRes);
            Dispatcher.addEventListener(EventName.Guide_BeginGame, this.onBeginGame);
            Dispatcher.addEventListener(EventName.Convey_Res, this.onConveyRes);
            Dispatcher.addEventListener(EventName.AI_NpcOutDestance, this.onOutNpcDistance);
            Dispatcher.addEventListener(EventName.Guide_UpdateCareer, this.onUpdateCareer);
            Dispatcher.addEventListener(EventName.Scene_Update, this.onSceneUpdateHandler);
            Dispatcher.addEventListener(EventName.Guide_ItemUsed, this.onGuideItemUsed);
            Dispatcher.addEventListener(EventName.Guide_FirstAttackHide, this.onFirstAttackHide);
            Dispatcher.addEventListener(EventName.PetBattleSuccess, this.onPetBattleSuccessHandler);
            Dispatcher.addEventListener(EventName.PetBattle, this.onPetBattleHandler);
            Dispatcher.addEventListener(EventName.ShopClose, this.onShopCloseHandler);
            Dispatcher.addEventListener(EventName.WareClose, this.onWareCloseHandler);
            Dispatcher.addEventListener(EventName.SkillWindowClose, this.onSkillWindowCloseHandler);
            Dispatcher.addEventListener(EventName.PetWindowClose, this.onPetWindowCloseHandler);
            Dispatcher.addEventListener(EventName.Equipment_WindowClose, this.onEquipmentWindowCloseHandler);
            Dispatcher.addEventListener(EventName.GuildApplySuccess, this.onGuildApplySuccessHandler);
            Dispatcher.addEventListener(EventName.PackWindowClose, this.onPackWindowCloseHandler);
            Dispatcher.addEventListener(EventName.AI_FightInDistance, this.onAIFightInDisHandler);
            Dispatcher.addEventListener(EventName.BeginToFight, this.onAutoFightBeginHandler);
            Dispatcher.addEventListener(EventName.BeginToFightShortcut, this.onAutoFightBeginHandler);
            RolePlayer.instance.addEventListener(PlayerEvent.PLAYER_FIRE, this.onPlayerFireHandler);
            NetDispatcher.addCmdListener(ServerCommand.Copy_ProcessUpdate, this.onCopyProcessUpdate);
            RolePlayer.instance.addEventListener(PlayerEvent.GIRD_WALK_END, this.onGridWorkEnd);
            Dispatcher.addEventListener(EventName.CopyCopyReset, this.onCopyResetHandler);
            
        }

        override protected function initView() : IView
        {
            return super.initView();
        }

    }
}
